Skip to content

fix(safety): deny file-writing and exec flags in default-allowed tools - #2

Merged
DavidLiedle merged 1 commit into
mainfrom
harden-write-flags
Sep 18, 2026
Merged

DavidLiedle merged 1 commit into
mainfrom
harden-write-flags

Conversation

@DavidLiedle

Copy link
Copy Markdown
Contributor

Follow-up to #1. The default read-only allowlist still let a few commands write files or run programs:

  • find -fprint/-fprint0/-fprintf/-fls create or truncate arbitrary paths. Working-directory containment only covers the cwd, not arguments.
  • rg --pre CMD runs CMD once per searched file.
  • git diff/log/show --output=PATH writes to PATH.
  • tree -o PATH / --output writes to PATH, including bundled short flags like -ao.

The find flags join the existing hard denylist. The others are scoped to their program (matched on the basename of the first token), so grep -o, rg --pretty, and similar stay allowed.

This also runs rustfmt over the tests from #1, which currently fail cargo fmt --check.

Tested: safety.rs compiles, passes clippy with -D warnings, and all 12 unit tests pass (standalone build with thiserror and shlex). CI here covers the full crate.

Extends the hard denylist beyond find's -exec family (#1):

- find: -fprint, -fprint0, -fprintf, -fls write arbitrary files
  anywhere on disk; cwd containment only covers the working directory.
- rg --pre CMD runs CMD for every searched file.
- git diff/log/show --output=PATH writes to PATH.
- tree -o / --output writes to PATH (including bundled -ao).

Program-specific flags are matched against the basename of the first
token so they don't collide with unrelated uses (grep -o, rg --pretty).

Also applies rustfmt to the tests added in #1 so `cargo fmt --check`
passes on main again.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6253c9b6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/safety.rs
/// an exact token or as the `flag=value` form.
const PROGRAM_DENY: &[(&str, &str)] = &[
// `rg --pre CMD` runs CMD once per searched file: arbitrary execution.
("rg", "--pre"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Deny ripgrep's hostname executable flag

When the launch tree contains an executable script, the default rg ** rule still permits arbitrary execution through a matching search such as rg --hostname-bin ./payload --hyperlink-format 'file://{host}{path}' --color always PATTERN .. Ripgrep 15.1.0's --help explicitly documents that --hostname-bin=COMMAND runs the supplied executable, and this check only denies --pre, so the new protection leaves another default-allowed execution path open; add --hostname-bin to the program-specific deny entries.

Useful? React with 👍 / 👎.

@DavidLiedle
DavidLiedle merged commit 6678b06 into main Sep 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant